package com.dlc.toolkit.distribution

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.dlc.toolkit.R

class RecyclerViewAdapter : RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>() {

    private var data: List<String?>? = null

    fun setData(data: List<String?>) {
        this.data = data
    }

    class ViewHolder : RecyclerView.ViewHolder {
        var tv_name: TextView? = null

        constructor(view: View) : super(view) {
            tv_name = view.findViewById(R.id.tv_name)
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view: View =
            LayoutInflater.from(parent.context).inflate(R.layout.item_rv, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.tv_name?.text = data?.get(position)
    }

    override fun getItemCount(): Int {
        return data?.size ?: 0
    }
}